package com.holly.unit.system.modular.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.holly.unit.system.modular.user.entity.SysUserRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 系统用户角色mapper接口
 *
 * @author holly
 * @date 2020/11/6 14:50
 */
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {

    @Select("SELECT r.role_code FROM sys_user_role ur JOIN sys_role r ON ur.role_id = r.role_id WHERE ur.user_id = #{userId}")
    List<String> findRoleCodesByUserId(@Param("userId")Long userId);

    @Delete({
            "<script>",
            "DELETE  FROM   sys_user_role WHERE  user_id  in " +
            "<foreach collection='userIds' item='item' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"
            })
    void deleteByUserIds(@Param("userIds")List<Long> userIds);

}

